using net_work.Common.Request;
using net_work.Common.Result;
using net_work.Data.DTO.Hmw;
using net_work.Data.Entity.Hmw;
using net_work.Data.VO.Hmw;
using net_work.IRepository.Cou;
using net_work.IRepository.Hmw;
using net_work.IService.Hmw;

namespace net_work.Service.Hmw;

public class BankQuestionService(IBankQuestionRepository bankQuestionRepository, ICourseRepository courseRepository)
    : IBankQuestionService
{
    public Task<PagedResult<BankQuestionResult>> GetBankQuestionsPagedAsync(PagedRequest request)
    {
        return bankQuestionRepository.GetBankQuestionPagedAsync(request);
    }

    public Task<BankQuestion?> SelectByIdAsync(long bankQuestionId)
    {
        return bankQuestionRepository.GetByIdAsync(bankQuestionId);
    }

    public async Task<long> InsertBankQuestion(BankQuestionAddRequest bankQuestionAddRequest)
    {
        var course = await courseRepository.GetByIdAsync(bankQuestionAddRequest.CourseId);
        if (course == null)
        {
            return -1;
        }

        return await bankQuestionRepository.InsertAsync(bankQuestionAddRequest);
    }

    public async Task<int> UpdateBankQuestion(BankQuestionUpdateRequest bankQuestionUpdateRequest)
    {
        if (bankQuestionUpdateRequest.Id <= 0)
        {
            return -1;
        }

        var course = await courseRepository.GetByIdAsync(bankQuestionUpdateRequest.CourseId);
        if (course == null)
        {
            return -1;
        }

        return await bankQuestionRepository.UpdateAsync(bankQuestionUpdateRequest) ? 1 : -1;
    }

    public async Task<int> DeleteBankQuestionByIds(List<long> ids)
    {
        return await bankQuestionRepository.DeleteByIdsAsync(ids) ? 1 : -1;
    }
}